/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package net.tygzs.minerpg.CommandExecutor.MineItem;

import java.util.ArrayList;
import java.util.List;
import net.md_5.bungee.api.ChatColor;
import net.tygzs.minerpg.Configuration.Item.RPGItem;
import net.tygzs.minerpg.Main;
import org.bukkit.command.CommandSender;

/**
 *
 * @author thtTNT
 */
public class Command_Lore
{

    public static void sendLores(CommandSender sender, String ItemName)
    {
        RPGItem ri = Main.getPluginConfig().getItem(ItemName);
        if (ri == null)
        {
            sender.sendMessage(ChatColor.RED + "物品不存在");
            return;
        }
        int index = 0;
        if (ri.getLores() == null)
        {
            sender.sendMessage(ChatColor.GREEN + "本物品没有添加任何lore");
            return;
        }
        for (String lore : ri.getLores())
        {
            sender.sendMessage(ChatColor.GREEN + "" + index + ":" + ChatColor.WHITE + lore);
        }
    }

    public static void editLore(CommandSender sender, String ItemName, int index, String lore)
    {
        if (Main.getPluginConfig().getItem(ItemName) == null)
        {
            sender.sendMessage(ChatColor.RED + "物品不存在");
            return;
        }
        RPGItem ri = Main.getPluginConfig().getItem(ItemName);
        if (ri.getLores() == null)
        {
            sender.sendMessage(ChatColor.GREEN + "本物品没有添加任何lore");
            return;
        }
        if (index >= ri.getLores().size())
        {
            sender.sendMessage(ChatColor.RED + "没有找到指定标号");
            return;
        }
        if (lore==null){
            Main.getPluginConfig().getItem(ItemName).getLores().remove(index);
            sender.sendMessage(ChatColor.GREEN+"删除成功");
            return;
        }
        Main.getPluginConfig().getItem(ItemName).getLores().set(index, lore);
        sender.sendMessage(ChatColor.GREEN + "修改成功");
    }

    public static void addLore(CommandSender sender, String ItemName, String lore)
    {
        if (Main.getPluginConfig().getItem(ItemName) == null)
        {
            sender.sendMessage(ChatColor.RED + "物品不存在");
            return;
        }
        RPGItem ri = Main.getPluginConfig().getItem(ItemName);
        if (ri.getLores() == null)
        {
            List<String> lores = new ArrayList<>();
            lores.add(lore);
            Main.getPluginConfig().getItem(ItemName).setLores(lores);
            sender.sendMessage(ChatColor.GREEN + "添加成功");
            return;
        }
        Main.getPluginConfig().getItem(ItemName).getLores().add(lore);
        sender.sendMessage(ChatColor.GREEN + "添加成功");
    }
    public static void delLore(CommandSender sender,String ItemName,int index){
        if (Main.getPluginConfig().getItem(ItemName) == null)
        {
            sender.sendMessage(ChatColor.RED + "物品不存在");
            return;
        }
        RPGItem ri = Main.getPluginConfig().getItem(ItemName);
        if (ri.getLores()==null){
            sender.sendMessage(ChatColor.RED+"该物品没有lore");
            return;
        }
        if (index >= ri.getLores().size()){
            sender.sendMessage(ChatColor.RED+"标号不存在");
        }
        Main.getPluginConfig().getItem(ItemName).getLores().remove(index);
        sender.sendMessage(ChatColor.GREEN+"删除成功");
    }
}
